package test2;

import java.util.Random;



public class demo1 {
    static int singular=0;
    static int dual=0;
    public static void main(String[] args) throws InterruptedException {
        int[] arr=new int[10000000];
        Random random=new Random();
        Object locker=new Object();

        for(int i=0;i<10000000;i++){
            int randomNumber = random.nextInt(100) + 1;
            arr[i]=randomNumber;
        }

        Thread t1=new Thread(()->{
            for(int i=0;i<10000000;i++){
                if(arr[i]%2==0){
                    dual+=arr[i];
                }
            }
        });
        Thread t2=new Thread(()->{
            for(int i=0;i<10000000;i++){
                if(arr[i]%2==1){
                    singular+=arr[i];
                }
            }
        });

        long startTime = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long endTime=System.currentTimeMillis();

        System.out.println("singular="+singular);
        System.out.println("dual="+dual);
        System.out.println("sum="+(singular+dual));

        System.out.println("执行时间:"+(endTime-startTime));
    }

    
}
